#ifndef DAOMANAGER_H
#define DAOMANAGER_H
#include <QObject>
#include "category.h"
#include "categorydao.h"
#include "moneydao.h"
#include "userdao.h"
#include "goaldao.h"

class SpecificSearch;

class DaoManager : public QObject
{
    Q_OBJECT
    Q_PROPERTY(SpecificSearch* spSearch READ spSearch WRITE setSpSearch NOTIFY spSearchChanged)

public:
    DaoManager();
    SpecificSearch* spSearch();
    void setSpSearch(SpecificSearch* sp);

    Q_INVOKABLE bool login(QString username, QString password);
    Q_INVOKABLE bool createUser(QString username, QString password);
    Q_INVOKABLE QList<QObject*> getAllCategories();
    Q_INVOKABLE QList<QObject*> addCategory(QString category);
    Q_INVOKABLE QList<QObject*> removeCategory(int index);
    Q_INVOKABLE QList<QObject*> updateCategory(QString name, int index);
    Q_INVOKABLE QString today();
    Q_INVOKABLE QString currentDate();
    Q_INVOKABLE QString previousDate();
    Q_INVOKABLE QString nextDate();
    Q_INVOKABLE QList<QObject*> getAllMoneyRegister();
    Q_INVOKABLE QList<QObject*> addMoney(int tipo, int idCategoria, QString description, double amount, QString date);
    Q_INVOKABLE QList<QObject*> updateMoneyRegister(int type, int idCategory, QString description, double amount, QString date);
    Q_INVOKABLE QList<QObject*> removeMoneyRegister(int index);
    Q_INVOKABLE QList<QObject*> getAllTypeMoney();
    Q_INVOKABLE void setMoney2BeEdited(int index);
    Q_INVOKABLE Money* money2BeEdited();
    Q_INVOKABLE float totalIncomes();
    Q_INVOKABLE float totalOutcomes();
    Q_INVOKABLE float totalCashFlow();
    Q_INVOKABLE void updateTotalByCategory();
    Q_INVOKABLE void setMoneyType(int typeMoney);
    Q_INVOKABLE void setTypeDate(int typeDate);
    Q_INVOKABLE QList<QObject*> getAllDatePeriods();
    Q_INVOKABLE void createCsvFile();
    Q_INVOKABLE QList<QObject*> getAllGoals();
    Q_INVOKABLE QList<QObject*> addGoal(int type, float target, QString initialDate, QString finalDate, QString description);
    Q_INVOKABLE QList<QObject*> removeGoal(int index);
    Q_INVOKABLE QList<QObject*> updateGoal(int type, float target, QString initialDate, QString finalDate, QString description, int index);
    Q_INVOKABLE QList<QObject*> getAllTypeGoal();
signals:
    void spSearchChanged();
private:
    MoneyUser* m_user;
    Money* m_money2BeEdited;
    QDate m_currentSelectedDate;
    QList<MoneyCategory*> m_listCategory;
    QList<Money*> m_listCurrentSeenMoney;
    QList<MoneyGoal*> m_listGoal;
    QList<float> m_totalList;
    int m_typeMoney;
    int m_typeDate;
    int m_semaphorMoney;
    SpecificSearch* m_spSearch;
    QList<MoneyCategory*> m_listDatePeriods;

    QList<QColor> m_colorList;
    QList<QString> m_colorNameList;

    void updatePeriod();
    void updateCategoryColors();
    void updateDatePeriodList();
    SpecificSearch* updateSpSearch(int typeDate, SpecificSearch* sp_Search = 0);
    QString getCurrentDateString(int typeDate,  SpecificSearch* sp_Search = 0);
};

#endif // DAOMANAGER_H
